import * as actionTypes from "./constants";

import { getHotAlbums, getAllAlbums } from "@/services/album";

const changeHotAlbumAction = (hotAlbum) => ({
  type: actionTypes.CHANGE_HOT_ALBUM,
  hotAlbum
});

const changeAllAlbumAction = (allAlbum) => ({
  type: actionTypes.CHANGE_ALL_ALBUM,
  allAlbum
});

/**
 * 热门新碟
 */
export function getHotAlbumsAction() {
  return dispatch => {
    getHotAlbums().then(res => {
      dispatch(changeHotAlbumAction(res.albums));
    })
  }
};

/**
 * 全部新碟
 */
export function getAllAlbumsAction(page) {
  return dispatch => {
    getAllAlbums((page - 1) * 30, 30).then(res => {
      dispatch(changeAllAlbumAction(res));
    })
  }
};